class Solution {
public:
    string reverseWords(string s) {
        auto pre = s.begin();
        vector<std::string::iterator> v;
        v.push_back(s.begin());
        while (pre != s.end())
        {
            pre = find(pre, s.end(), ' ');
            if (pre == s.end())
            {
                break;
            }
            pre++;
            v.push_back(pre);
        }
        int des = 0;
        while (des < v.size())
        {
            if (des == v.size() - 1)
            {
                reverse(v[des], s.end());
                break;
            }
            std::reverse(v[des], v[des + 1] - 1);
            des++;
        }
        return s;
    }
};